package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

type BaseController struct {
}

type ResponseData struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

func (con BaseController) Success(c *gin.Context, res ...interface{}) {

	if reslen := len(res); reslen == 1 {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  res[0],
			"data": []string{},
		})

	} else if reslen == 2 {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  res[0],
			"data": res[1],
		})
	} else if reslen == 3 {
		c.JSON(http.StatusOK, gin.H{
			"code":  1,
			"msg":   res[0],
			"data":  res[1],
			"count": res[2],
		})
	} else if reslen == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  "Success",
			"data": []string{},
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 1,
			"msg":  res[0],
			"data": []string{},
		})

	}

}

func (con BaseController) Error(c *gin.Context, res ...interface{}) {

	var code int8 = 0
	if reslen := len(res); reslen == 1 {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  res[0],
			"data": []string{},
		})

	} else if reslen == 2 {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  res[0],
			"data": res[1],
		})
	} else if reslen == 0 {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  "Error",
			"data": []string{},
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  res[0],
			"data": []string{},
		})

	}
}
